﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using NUnit.Framework;
using posttracker.Classes;
namespace nUnitTests
{
    public class RegistrationTests
    {
        [Test]
        public void TestUpdateUser()
        {
            //posttracker.Classes.User user = new posttracker.Classes.User() { Id = 1, UserName = "Jam", Password = "1234", RoleId = 1, Email = "Jam@tut.by" };

            //Assert.Throws(typeof(HttpRequestException), posttracker.Classes.Registration.Update(user));

            //Assert.That(posttracker.Classes.Registration.Update(user), Throws.HttpRequestException);
            //Registration reg = new Registration();
            //var user = new User() { Id = 1, Password = "1234", RoleId = 1, Email = "Jam@tut.by" };
            //user.SetUserName("Jam");
            //Assert.DoesNotThrow(() => { reg.Update(user); });
            //Registration.update(user);
            //User user = new User() { Email = "Jamy@tut.by", Id = 21 };
            //user.SetUserName("Jamy");
            
            //Assert.DoesNotThrow(() => { posttracker.Classes.Registration.Update(user, 1); });

            WebApiMembershipProvider mem = new WebApiMembershipProvider();

            User user = new User() { Email = "Jamy@tut.by", Id = 21 };
            user.SetUserName("Jamy");
            Assert.DoesNotThrow(() => { mem.UpdateUser(user); });
            //Registration reg = new Registration();

            
            //Assert.DoesNotThrow(() => { mem.UpdateUser(user); });
            //Assert.That(posttracker.Classes.Registration.Update(user), Throws.HttpRequestException);
            
        }

        [Test]
        public void TestRegisterUser()
        {
      
            //Assert.That(() => { posttracker.Classes.Registration.Register(new {UserName = "Jam", Password = "1234", Email = "Jam@tut.by" }); }, Is.EqualTo(0));
            User user = new User() { Password = "1234", Email = "Jam@tut.by" };
            user.SetUserName("Jam");

            Registration reg = new Registration();
            Assert.True(((int) reg.Register(ref user)) == 0);
            //reg.Register(ref user);
            Assert.Greater(user.Id,0);
        }

        [Test]
        public void TestGetUserByEmail()
        {


            Registration reg = new Registration();
            Assert.DoesNotThrow(() => { reg.GetUserByEmail("Jam@tut.by"); });
        }

        [Test]
        public void TestDeleteUser()
        {
            
            Registration reg = new Registration();
            Assert.True(reg.DeleteUser("Jam@tut.by", false));
        }

        [Test]
        public void TestAuthUser()
        {

            Registration reg = new Registration();
            Assert.True(reg.ValidateUser("Jam@tut.by", "1234"));
        }

        [Test]
        public void TestGetUser()
        {

            Registration reg = new Registration();
            Assert.True(reg.GetUser(1, true) != null);
            Assert.True(reg.GetUser("Jam", true) != null);
        }

    
    }
}
